package com.xiaobaibai.controller;

import com.xiaobaibai.common.response.ResponseFormat;
import com.xiaobaibai.pojo.TimeLine;
import com.xiaobaibai.server.timeline.ITimeLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class TimelineController {

    @Autowired
    private ITimeLineService timeLineService;

    @GetMapping("/getTimelineList")
    public ResponseFormat getTimeline(){
        List<TimeLine> timeline = timeLineService.getTimeline();
        return ResponseFormat.createSuccessResponse("success",timeline);
    }

    @PostMapping("/addTimeline")
    public ResponseFormat addTimeline(@RequestBody Map data){
        String content= (String) data.get("content");
        TimeLine timeLine = timeLineService.addTimeline(content);
        return ResponseFormat.createSuccessResponse("success",timeLine);
    }

    @PostMapping("/delTimeline")
    public ResponseFormat delTimeline(@RequestParam("id")Integer id){
        timeLineService.delTimeline(id);
        return ResponseFormat.createSuccessResponseOnlyMessage("success");
    }

}
